package day01.day02;

import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Scanner;

/**
 * @author feng
 * @Date 2021/12/24 11:40
 */
public class PrintCalenDar {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个月份的年、月、日");
        int year = sc.nextInt();
        int month = sc.nextInt();
        //得到本月的第一天日期
        LocalDate dates = LocalDate.of(year, month, 1);
        String monthName = dates.getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault());
        //返回当前月的天数
        int days0fMonth = dates.lengthOfMonth();
        System.out.println(year + "年       " + monthName);
        System.out.println("------------------------------");
        System.out.printf("%10s%10s%10s%10s%10s%10s%10s%n", "一", "二", "三", "四", "五", "六", "日");
        //返回1月1号是周几，返回1是周1，返回7是周日
        int dayofWeek = dates.getDayOfWeek().getValue();
        //输出前导空格
        for (int i = 2; i < dayofWeek; i++) {
            System.out.printf("%4s", " ");
        }
        //输出日期
        for (int i = 1; i <= days0fMonth; i++) {
            System.out.printf("%4d", i);
            if ((dayofWeek + i - 1) % 7 == 0) {
                System.out.println();
            }
        }

    }

}
